package cn.java78.springboot.myschool.printer;

/**
 * @author oldliu
 * @since 1.0
 */
public class TextPaper {
    //一页能打几行，一行几个字
    private int lines;
    private int words;
    //打印
    public void print(String s){
        char[] chars = s.toCharArray();
        int l=0,w=0;//计数
        int pageNo=1;
        for(char c:chars){
            System.out.print(c);
            w++;
            if(w>=words){
                //一行到头
                System.out.println();
                l++;
                w=0;
                if(l>=this.lines){
                    //一页打完了，换页
                    l=0;
                    System.out.println("--"+pageNo+"--");
                    pageNo++;
                }
            }
        }
        if(l>0||w>0){
            System.out.println("\n--"+pageNo+"--");
        }
    }

    public void setLines(int lines) {
        this.lines = lines;
    }

    public void setWords(int words) {
        this.words = words;
    }

    public int getLines() {
        return lines;
    }

    public int getWords() {
        return words;
    }

    @Override
    public String toString() {
        return "TextPaper{" +
                "lines=" + lines +
                ", words=" + words +
                '}';
    }
}
